import {
	PanelActionType,
	ICtrlDataAction,
	ICtrlEvent,
	IPanelAbility,
	IPanelControllerParams,
	IPanelModel,
	IPanelStore,
	IParam,
	IPanelController,
} from '@/core';
import { QXEvent } from 'qx-util';
import { PropType } from 'vue';
import {
	getCtrlClassNames,
	useCtrlAction,
	useCtrlBasic,
	useCtrlControllerParams,
	useCtrlProps,
} from '../use-ctrl';

/**
 * 面板输入参数
 *
 * @export
 * @return {*}
 */
export function usePanelProps() {
	return {
		...useCtrlProps(),
		openView: Function,
		newView: Function,
		data: Object as PropType<IParam>,
		viewType: String,
		isLoadDefault: Boolean,
		actions: Object as PropType<ICtrlDataAction>,
	};
}

/**
 * 面板基础参数
 *
 * @export
 * @param {IPanelModel} model
 * @param {IParam} props
 * @return {*}
 */
export function usePanelBasic(model: IPanelModel, props: IParam) {
	const getClassNames = (props: IParam) => {
		const names = getCtrlClassNames(model, props);
		Object.assign(names, {
			'panel-layout': true,
			[`panel-layout--${model.layoutMode.toLowerCase()}`]: true,
		});
		return names;
	};
	return {
		...useCtrlBasic(model, props),
		getClassNames,
	};
}

/**
 * 面板部件行为
 *
 * @export
 */
export function usePanelAction(
	controller: IPanelController<IPanelStore, IPanelAbility>
) {
	return {
		...useCtrlAction(controller),
	};
}

/**
 * 面板部件控制器
 *
 * @export
 */
export function usePanelControllerParams<
	S extends IPanelStore,
	M extends IPanelModel
>(
	model: M,
	props: any,
	evt: QXEvent<ICtrlEvent<PanelActionType, IPanelAbility>>,
	otherParams: IParam = {}
): IPanelControllerParams<PanelActionType, IPanelAbility> {
	return {
		...useCtrlControllerParams<S, M>(model, props, evt, otherParams),
		data: props.data,
		viewType: props.viewType,
		actions: props.actions,
		openView: props.openView,
		isLoadDefault: props.isLoadDefault,
		newView: props.newView,
	};
}
